/**
 * 初始化订单管理详情对话框
 */
var TOrderInfoDlg = {
    tOrderInfoData: {}
};


var orders = [];

function CloseWebPage() {
    if (navigator.userAgent.indexOf("MSIE") > 0) {
        if (navigator.userAgent.indexOf("MSIE 6.0") > 0) {
            window.opener = null;
            window.close();
        } else {
            window.open('', '_top');
            window.top.close();
        }
    }
    else if (navigator.userAgent.indexOf("Firefox") > 0) {
        window.location.href = 'about:blank ';
    } else {
        window.opener = null;
        window.open('', '_self', '');
        window.close();
    }
}

/**
 * 关闭此对话框
 */
TOrderInfoDlg.close = function () {
    CloseWebPage();
}

/**
 * 收集数据
 */
TOrderInfoDlg.collectData = function () {


}


/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
TOrderInfoDlg.set = function (key, val) {
    this.tOrderInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}
var is_ture = true;
/**
 * 提交添加
 */
TOrderInfoDlg.addSubmit = function () {

    jqPrint();

}

function jqPrint() {
    $("#myPrintArea").print({
        globalStyles: true,
        mediaPrint: true,
        stylesheet: null,
        noPrintSelector: ".no-print",
        iframe: false,
        append: null,
        prepend: null,
        manuallyCopyFormValues: true,
        deferred: $.Deferred()
    });
}

var mDate = null;
 function someFunction(m) {
    if (m) {
        mDate = m;
    }
    var sum = 0;
    var csum = 0;
    for (var i = 0; i < mDate.data.length; i++) {
        sum = sum + parseFloat(mDate.data[i].payment) + parseFloat(mDate.data[i].collection) + parseFloat(mDate.data[i].shf) + parseFloat(mDate.data[i].byf) + parseFloat(mDate.data[i].ccf) + parseFloat(mDate.data[i].extra_money);
        csum = csum + parseFloat(mDate.data[i].cf);
    }
    $('#cf').text(csum);
    $('#xj').text(sum - csum);
}

var aTable = null
var mTable = null;
$(function () {

    layui.use('table', function () {
        var table = layui.table;
        table.render({
            elem: '#PPtable'
            , url: Feng.ctxPath + "/tOrder/pDataList?ids=" + $('#ids').val()
            ,skin: 'row'
            ,size: 'sm',
            page: false
            , cols: [[
                {field: 'original_num', width: 120, title: '单号' }
                , {field: 'consignee', width: 100, title: '收货人'}
                , {field: 'goods_name', width: 90, title: '货物名称' }
                , {field: 'goods_piece', width: 54, title: '件数'}
                , {field: 'payment', width: 66, title: '提付'}
                , {field: 'collection', width: 54, title: '货款' }
                , {field: 'extra_money', width: 66, title: '落地费' }
                , {field: 'shf', width: 66, title: '送货费' }
                , {field: 'ccf', width: 66, title: '仓储费' }
                , {field: 'byf', width: 66, title: '搬运费' }
                , {field: '', width: 80,title: '合计收款' ,
                    templet: function (d) {
                    return parseFloat(d.payment).add(d.collection).add(d.extra_money).add(d.shf).add(d.ccf).add(d.byf);
                    }
                }
                , {field: 'cf', width: 66, title: '车费' },
                {field: 'notice', width: 78, title: '等通知发货',   templet: function (d) {
                    if(d.notice==1){
                        return "是";
                    }else {
                        return "";
                    }
                } }
                , {field: 'receipt', width: 80, title: '回单要求' }
            ]],
            done: function (res, curr, count) {
                someFunction(res)

            }
        });
    });


});
